package com.qijia.common.domain.example;

import java.util.ArrayList;
import java.util.List;

/**
 * 条件父类，用于查询、修改等数据操作的条件构造器
 * 
 * @author Administrator
 * 
 */
public abstract class BaseExample {
	/**
	 * 起始显示记录序号
	 */
	private int startLine = 0;

	/**
	 * 每页显示条数
	 */
	private int pageSize = 20;

	/**
	 * order by 关键字
	 */
	protected String orderByClause;

	/**
	 * 默认的Sql Mapped Id
	 */
	protected String countMapId = "countByExample";

	/**
	 * where 条件集
	 */
	protected List<BaseCriteria> oredCriteria;

	public int getStartLine() {
		return startLine;
	}

	public void setStartLine(int startLine) {
		this.startLine = startLine;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public BaseExample() {
		oredCriteria = new ArrayList<BaseCriteria>();
	}

	protected BaseExample(BaseExample example) {
		this.orderByClause = example.orderByClause;
		this.oredCriteria = example.oredCriteria;
	}

	public void setOrderByClause(String orderByClause) {
		this.orderByClause = orderByClause;
	}

	public String getOrderByClause() {
		return orderByClause;
	}

	public List<BaseCriteria> getOredCriteria() {
		return oredCriteria;
	}

	public void or(BaseCriteria criteria) {
		oredCriteria.add(criteria);
	}

	public BaseCriteria createCriteria() {
		BaseCriteria criteria = createCriteriaInternal();
		if (oredCriteria.size() == 0) {
			oredCriteria.add(criteria);
		}
		return criteria;
	}

	protected BaseCriteria createCriteriaInternal() {
		BaseCriteria criteria = getCriteria();
		return criteria;
	}

	public void clear() {
		oredCriteria.clear();
	}

	/**
	 * 具体实现放于子级中实现
	 * 
	 * @return
	 */
	protected abstract BaseCriteria getCriteria();

	public String getCountMapId() {
		return countMapId;
	}

	public void setCountMapId(String countMapId) {
		this.countMapId = countMapId;
	}
}
